/*
**      Newton Developer Technical Support Sample Code
**
**      ListPicker,  the basic listPicker displaying information from a user defined
**		soup.
**
**      by Stephen Harris, Newton Developer Technical Support
**
**      Copyright  1993-1996 by Apple Computer, Inc.  All rights reserved.
**
**      You may incorporate this sample code into your applications without
**      restriction.  This sample code has been provided "AS IS" and the
**      responsibility for its operation is 100% yours.  You are not
**      permitted to modify and redistribute the source as "DTS Sample Code."
**      If you are going to re-distribute the source, we require that you
**      make it clear in the source that the code was descended from
**      Apple-provided sample code, but that you've made changes.
*/

//  This sample demonstates the use of the protoListPicker and a user defined soup.
//  The user is to display soup entries only with no editing unless one of the entries
//  will not pass the validationFrame.

// the app stuff
constant kAppTitle := "The List Picker";

//--------------

// Soup stuff
constant kSoupName := kPackageName;
Constant kSoupIndexes := '[{structure: slot,path: first, type: string}];

// used in the listPicker querySpec slot
constant kQuerySpec := '{type: index, indexpath: first};

// used by the regUnionSoup function for soup design
DefConst('kSoupDef, {
	name: kSoupName,
	username: kAppName,
	ownerApp: kAppSymbol,
	userDescr: "Soup for the List Picker sample",
	indexes: kSoupIndexes
}) ;

//--------------


// Random  entry generator.
DefConst('kCanonicalEntry,
   {
		first: nil,
		second: nil,

	});


DefConst('kRandomDataGeneratorFunc, func()
	begin
		local item := clone(kCanonicalEntry);

		item.first := Capitalize(GetRandomWord(4, 12));
		item.second := Capitalize(GetRandomWord(4, 12));
		item;
	end);
		
//--------------

// DeleteScript->  this only gets called when your app is deleted and not
// when the card is removed.

SetPartFrameSlot('DeletionScript, func()
	begin
		//Remove the soup from the stores
		foreach store in GetStores() do 
		begin
			local theSoup := store:GetSoup(kSoupName);
			if theSoup then
			   theSoup:RemoveFromStore();
		end;
	end
);

// Install/Remove Scripts

InstallScript := func(part)
begin	
	RegUnionSoup(kAppSymbol, kSoupDef) ;
end;

RemoveScript := func(part)
begin 
	// unregister autocreation of soup
	UnRegUnionSoup(kSoupName, kAppSymbol);
end;

